import { createRouter, createWebHistory } from 'vue-router'

import UserListView from '@/views/user/ListView.vue'
import UserSaveView from '@/views/user/SaveView.vue'

import CourseListView from '@/views/course/ListView.vue'
import CourseSaveView from '@/views/course/SaveView.vue'

import EngineerListView from '@/views/engineer/ListView.vue'
import EngineerSaveView from '@/views/engineer/SaveView.vue'

import ProjectListView from '@/views/project/ListView.vue'
import ProjectSaveView from '@/views/project/SaveView.vue'

import ResourceTypeListView from '@/views/resourceType/ListView.vue'

import ResourceListView from '@/views/resource/ListView.vue'
import ResourceSaveView from '@/views/resource/SaveView.vue'


import SchoolListView from '@/views/school/ListView.vue'
import SchoolSaveView from '@/views/school/SaveView.vue'
  
const routes = [
  {
    path: '/',
    component: () => import('../views/layout/LayoutView.vue'),
    children: [
      {
        path: '/',
        redirect: '/user/list'
      },
      {
        path: '/user/list',
        name: 'userListView',
        component: UserListView
      },
      {
        path: '/user/save',
        name: 'userSaveView',
        component: UserSaveView
      },
      {
        path: '/resourceType/list',
        name: 'resourceTypeListView',
        component: ResourceTypeListView
      },{
        path: '/resource/list',
        name: 'resourceListView',
        component: ResourceListView
      },
      {
        path: '/resource/save',
        name: 'resourceSaveView',
        component: ResourceSaveView
      },
      {
        path: '/course/list',
        name: 'courseListView',
        component: CourseListView
      },
      {
        path: '/course/save',
        name: 'courseSaveView',
        component: CourseSaveView
      },
      {
        path: '/engineer/list',
        name: 'engineerListView',
        component: EngineerListView
      },
      {
        path: '/engineer/save',
        name: 'engineerSaveView',
        component: EngineerSaveView
      },
      {
        path: '/project/list',
        name: 'projectListView',
        component: ProjectListView
      },
      {
        path: '/project/save',
        name: 'projectSaveView',
        component: ProjectSaveView
      },
      {
        path: '/school/list',
        name: 'schoolListView',
        component: SchoolListView
      },
      {
        path: '/school/save',
        name: 'schoolSaveView',
        component: SchoolSaveView
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/schoolLogin',
    name: 'schoolLogin',
    component: () => import('../views/SchoolLoginView.vue')
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes
})

// router.beforeEach((to, from, next) => {
//   const token = sessionStorage.getItem('token')
//   const toPath = to.path
//   if (toPath == '/login') {
//     //判断是否已经登录过了
//     if (token) {
//       next({ path: '/user/list' })
//     } else {
//       next()
//     }
//   } else {
//     //判断是否已经登录
//     if (token) {
//       //已经登录了
//       next()
//     } else {
//       next({ path: '/login' })
//     }
//   }
// })

export default router
